<template>
    <div class="user-address">
        <van-address-list
                v-model="chosenAddressId"
                :list="list"
                default-tag-text="默认"
                @add="onAdd"
                @edit="onEdit"
        />
    </div>
</template>

<script>
    import { AddressList,Toast } from 'vant';
    import Vue from 'vue'
    import {ApiService} from "@/axios/apiService";
    Vue.use(AddressList,Toast);
    export default {
        data() {
            return {
                chosenAddressId: '1',
                list: [],
            };
        },
        mounted() {
          this.getAddressList()
        },
      methods: {
            getAddressList() {
              const api = new ApiService("/address/user")
              var userId = api.getCookie("userId")
              console.log("userId ="+userId)
              api.getParams({
                userId:userId
              }).then(res=> {
                console.log(res);
                var data = res.data.data
                console.log(data)
                data.forEach(item=> {
                  this.list.push({
                    id: item.id,
                    name: item.name,
                    tel: item.tel,
                    address: item.province+item.city+item.county+item.addressDetail,
                    isDefault: item.isDefault,
                  })
                })
              })

            },
            onAdd() {
               this.$router.push('/user/add/address')
            },
            onEdit(item, index) {
                Toast('编辑地址:' + index);
            },

        },
    };
</script>
